package com.example.liverock.androidalltest;

import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;

public class BirthdayActivity extends Activity {
    /**
     * 成员函数，年、月、日；
     */
    private int mYear;
    private int mMonth;
    private int mDay;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_birthday);

        DatePicker datePicker = (DatePicker)findViewById(R.id.datePicker);
        Button button = (Button)findViewById(R.id.button);
        /**
         * 获得当前的年、月、日
         */
        Calendar calendar = Calendar.getInstance();
        mYear = calendar.get(Calendar.YEAR); // 获取当前年份
        mMonth = calendar.get(Calendar.MONTH); // 获取当前月份
        mDay = calendar.get(Calendar.DATE); // 获取当前日
        /****
         * 首先初始化时间表，当数据变化时，记录变化的时间
         */
        datePicker.init(mYear, mMonth, mDay, new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker view, int year, int mMonthOfYear, int dayOfMonth) {
                mYear = year;
                mMonth = mMonthOfYear;
                mDay = dayOfMonth;
            }
        });
        /****
         * 计算星座的算法
         */
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = "";
                if ((mMonth == 3 && mDay > 20) || (mMonth == 4 && mDay < 21)) {
                    name = "您是白羊座！";
                } else if ((mMonth == 4 && mDay > 20) || (mMonth == 5 && mDay < 21)) {
                    name = "您是金牛座！";
                } else if ((mMonth == 5 && mDay > 20) || (mMonth == 6 && mDay < 22)) {
                    name = "您是双子座！";
                } else if ((mMonth == 6 && mDay > 21) || (mMonth == 7 && mDay < 23)) {
                    name = "您是巨蟹座！";
                } else if ((mMonth == 7 && mDay > 22) || (mMonth == 8 && mDay < 23)) {
                    name = "您是狮子座！";
                } else if ((mMonth == 8 && mDay > 22) || (mMonth == 9 && mDay < 23)) {
                    name = "您是处女座！";
                } else if ((mMonth == 9 && mDay > 22) || (mMonth == 10 && mDay < 23)) {
                    name = "您是天平座！";
                } else if ((mMonth == 10 && mDay > 22) || (mMonth == 11 && mDay < 22)) {
                    name = "您是天蝎座！";
                } else if ((mMonth == 11 && mDay > 21) || (mMonth == 12 && mDay < 22)) {
                    name = "您是射手座！";
                } else if ((mMonth == 12 && mDay > 21) || (mMonth == 1 && mDay < 20)) {
                    name = "您是摩羯座！";
                } else if ((mMonth == 1 && mDay > 19) || (mMonth == 2 && mDay < 19)) {
                    name = "您是水牛座！";
                } else if ((mMonth == 2 && mDay > 18) || (mMonth == 3 && mDay < 21)) {
                    name = "您是双鱼座！";
                }
                name = mMonth + "月" + mDay + "日  " + name;
                Toast.makeText(BirthdayActivity.this, name, Toast.LENGTH_SHORT).show();
            }
        });
    }
}